/*
 * Copyright 2009 Vladimir Ritz Bossicard
 *
 * This file is part of OraDoc.
 *
 * OraDoc is free software: you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * Version     : $Revision: 20 $
 * Last edit   : $Date: 2009-03-25 12:43:30 +0000 (Wed, 25 Mar 2009) $
 * Last editor : $Author: vbossica $
 */
package org.oradoc.config;

import javax.sql.DataSource;

import org.oradoc.structures.dao.TableDao;
import org.oradoc.structures.dao.TableDbDao;
import org.oradoc.structures.dao.ViewDao;
import org.oradoc.structures.dao.ViewDbDao;
import org.springframework.config.java.annotation.Bean;
import org.springframework.config.java.annotation.Configuration;
import org.springframework.config.java.annotation.ExternalValue;
import org.springframework.config.java.annotation.valuesource.SystemPropertiesValueSource;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

/**
 *
 * @author Vladimir Ritz Bossicard
 */
@Configuration
@SystemPropertiesValueSource
public class DefaultConfiguration extends AbstractConfiguration {

    @ExternalValue("oradoc.connection")
    private String connection;
    @ExternalValue("oradoc.username")
    private String username;
    @ExternalValue("oradoc.password")
    private String password;

    @Bean
    public TableDao tableDao() {
        TableDbDao tableDao = new TableDbDao();
        tableDao.setDataSource(datasource());

        return tableDao;
    }

    @Bean
    public ViewDao viewDao() {
        ViewDbDao viewDao = new ViewDbDao();
        viewDao.setDataSource(datasource());

        return viewDao;
    }

    @Bean
    public DataSource datasource() {
        DriverManagerDataSource ds = new DriverManagerDataSource();
        ds.setDriverClassName("oracle.jdbc.OracleDriver");
        ds.setUrl(this.connection);
        ds.setUsername(this.username);
        ds.setPassword(this.password);

        return ds;
    }

}
